import unittest
from Page.Page import Page
from selenium import webdriver
from Page.Page02 import Page02
from MyDB.a3mall_db import db
from tools.tool import tool


class TestCase(unittest.TestCase):
    def setUp(self):
        #初始化数据库连接
        self.msq=db(user='root',password='yidong666',host='10.59.9.12',databases='a3mall')
        self.driver=webdriver.Firefox()
        #窗口最大化
        self.driver.maximize_window()
        tool().Log()

    def tearDown(self):
        time.sleep(3)
        self.driver.quit()

    def test_A3mall_01(self):
        #po模型
        po=Page(self.driver)
        po.A3mall_login_01()


    def test_A3mall_02(self):
        #po模型
        po=Page02(self.driver)
        po.A3mall_search_02()
        yqDB = self.msq.select("select amount from mall_users where username='liu121212'")
        print("余额是：", str(yqDB[0][0]))

if __name__ == '__main__':
    unittest.main()



import time
# import pytest
# from Page.Page import Page  # 假设这些自定义模块路径正确
# from selenium import webdriver
# from Page.Page02 import Page02
# from MyDB.a3mall_db import db
#
# # fixture 实现前置后置，scope="function" 表示每个测试函数执行前都会执行
# @pytest.fixture(scope="function")
# def driver_setup_teardown():
#     msq = db(user='root', password='yidong666', host='10.59.9.12', databases='a3mall')
#     driver = webdriver.Firefox()
#     driver.maximize_window()
#     yield driver, msq
#     driver.quit()
#
#
# def test_A3mall_01(driver_setup_teardown):
#     driver, msq = driver_setup_teardown
#     po = Page(driver)
#     po.A3mall_login_01()
#
#
# def test_A3mall_02(driver_setup_teardown):
#     driver, msq = driver_setup_teardown
#     po = Page02(driver)
#     po.A3mall_search_02()
#     # 数据库查询
#     yqDB = msq.select('select amount from mall_users where username="liu121212"')
#     print("余额：", str(yqDB[0][0]))
#
#
# if __name__ == "__main__":
#     pytest.main(["-s", "当前脚本文件名.py"])


